program ReadWriteDelete;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement = ^element;
  element = record
    value: Integer;
    next: pelement;
  end;

procedure Add (var head: pelement; num: Integer);
var
  tmp: pelement;
begin
  tmp:=head;
  New(head);
  head^.next:=tmp;
  head^.value:=num;
end;

procedure AddToEnd (var head: pelement; num: Integer);
var
  current: pelement;
begin
  if (head <> nil) then
  begin
    current:=head;
    while (current^.next <> nil) do
    begin
      current:=current^.next;
    end;
    New(current^.next);
    current^.next^.value:=num;
    current^.next^.next:=nil;
  end else begin
    Add (head, num);
  end;
end;

procedure PrintList (head: pelement);
var
  current: pelement;
begin
  current:=head;
  while (current <> nil) do
  begin
    writeln(current^.value);
    current:=current^.next;
  end;
end;

function Delete (var head:pelement): integer;
var
  tmp: pelement;
begin
  if (head <> nil) then
  begin
    tmp:=head^.next;
    Delete:=head^.value;
    Dispose(head);
    head:=tmp;
  end;
end;

var
  head: pelement;
  fin: TextFile;
  n, k, i: Integer;

begin
  AssignFile (fin, 'input.txt');
  Reset (fin);
  Read (fin, n);
  for i:=1 to n do
  begin
    read (fin, k);
    AddToEnd (head, k);
  end;
  PrintList (head);
  for i:=1 to n do
  begin
    Delete (head);
  end;
  CloseFile(fin);
  Readln;
end.
